package actions;

import models.ItemModel;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import service.ItemService;

import com.opensymphony.xwork2.ModelDriven;

@ParentPackage("json-default")
public class ItemAction extends CoreAction implements ModelDriven<ItemModel> {
	private static final long serialVersionUID = 1L;
	private static final Logger LOGGER = Logger.getLogger(ItemAction.class);
	private ItemService itemService;
	private ItemModel model;

	@Autowired
	public void setModel(ItemModel model) {
		this.model = model;
	}

	@Autowired
	public void setItemService(ItemService itemService) {
		this.itemService = itemService;
	}

	public String execute() {
		return SUCCESS;
	}

	@Action(value = "getItems", results = { @Result(name = "success", type = "json") })
	public String getAll() {
		LOGGER.info("Start action: getItems");
		//model.setList(itemService.getAll());
		LOGGER.info("End action: getItems");
		return SUCCESS;
	}

	public ItemModel getModel() {
		return model;
	}
}
